#ifndef SunWindowPort_First
#define SunWindowPort_First
#ifdef __GNUG__
#pragma interface
#endif

#include "WindowPort.h"
#include "SunWindowSystem.h"
#include "SunColorMap.h"
#include "SunBitmap.h"

class SunInputHandler;
struct pixwin;
struct pixrect;
struct pw_pixel_cache;
struct pr_pos;

//---- SunWindowPort -----------------------------------------------------------

class SunWindowPort: public WindowPort {
public:
	MetaDef(SunWindowPort);
	SunWindowPort(Window *bw, WindowType wt, GrCursor curs);
	~SunWindowPort();

	int DevGetId();
	void DevClip(const Rectangle&);
	void DevStrokeLine2(int, const Rectangle&, GrLineCap, const Point&,
								const Point&);
	void DevStrokeRect2(int, const Rectangle&);
	void DevFillRect(const Rectangle&);
	void DevStrokeRRect2(int, const Rectangle&, const Point&);
	void DevFillRRect2(const Rectangle&, const Point&);
	void DevStrokePolygon2(const Rectangle&, Point*, int, GrPolyType, int, GrLineCap);
	void DevFillPolygon2(const Rectangle&, Point*, int, GrPolyType);
	void DevShowBitmap(const Rectangle&, Bitmap*);
	void DevShowChar(Font*, const Point&, Rune, const Rectangle&);
	void DevShowTextBatch(const Rectangle&, const Point&);
	void DevSetPattern(Bitmap*);
	void DevSetColor2(u_long);
	void DevSetOther(int);
	void DevGiveHint(int, int, void*);

	void DevSetCursor(GrCursor);

	void DevFullscreen(bool);

	void DevScrollRect(const Rectangle&, const Point&);

	void DevTop(bool);
	void DevHide();
	void DevShow(WindowPort *father, const Rectangle&);
	void DevIconize();

	Rectangle DevGetRect();
	void DevSetExtent(const Point&);
	void DevSetOrigin(const Point&);

	bool NextEvent(Token *t);
	bool NextEvent2(Token *t);
	void DevSetMousePos(const Point&, bool);

	void DevBell(long);

	void DevSetTitle(const char*);

	void TestDamage();
	bool Notify();

private:
	void lock(const Rectangle &r);
	void BitBlt(int x, int y, int w, int h);
	void line(int psz, int x0, int y0, int x1, int y1);
	void PolyDot(pixrect *pr, int dx, int dy, pr_pos *pts, int n, int psz);
	void PolyEllipse(pixrect *pr1, int x0, int y0, int x1, int x2,
						int y1, int y2, int a, int b, int psz);
	void Bresenham(pixrect *pr1, int fromX, int fromY, int X2, int Y2, int psz);
	pixrect *GetPattern(const Point &e);
	void Stencil(const Rectangle &r, pixrect *pr);

public:
	int fd, num, tmode, cmode;
	Point inpOffset;
	pixwin *pw, *opw, *rpw;
	pixrect *pr, *opr, *rpr, *pat;
	pw_pixel_cache *savepr;
	SunWindowPort *fatherport;
	bool inbatch, color;
	SunBitmap *patbm;
	SunInputHandler *inputhandler;
};

#endif

